import { NextFunction, Request, Response } from 'express';

// html form action 兼容更多请求方式，通过body的_method属性
export function MethodOverridesMiddleware(
  req: Request,
  res: Response,
  next: NextFunction,
) {
  if (req.body && typeof req.body === 'object' && '_method' in req.body) {
    req.method = req.body._method.toUpperCase();
    delete req.body._method;
  }
  next();
}
